/*
 * @lc app=leetcode id=452 lang=cpp
 *
 * [452] Minimum Number of Arrows to Burst Balloons
 */

// @lc code=start
class Solution {
public:
    int findMinArrowShots(vector<vector<int>>& points) {
        sort(points.begin(), points.end(), [](const vector<int> &lhs, const vector<int> &rhs){
            return lhs[1] < rhs[1] || (lhs[1] == rhs[1] && lhs[0] < rhs[0]);
        });
        int ans = 0;
        for (int i = 0; i < points.size();) {
            int right = points[i][1];
            ans++;
            int flag = 0;
            for (int j = i + 1; j < points.size(); ++j) {
                if (points[j][0] > right) {
                    i = j;
                    flag = 1;
                    break;                
                }
            }
            if(flag == 0) {
                break;
            }
        }
        return ans;
    }
};
// @lc code=end

